package CClass;

use Set;
use Signature;
use CConstructor;
use CArg;

sub new {
	my ($class, $signature, $file) = @_;
	$file = '' if (!$file); 
	return bless { sig => $signature, consturctors => new Set(), defaultConstructor => new CConstructor('', 1), file=>$file }, $class;
}

sub clone {
	my $this = shift;
	my $copy = new CClass($this->{sig}, $this->{file});
	$copy->{consturctors} = $this->{consturctors};
	return $copy;
}

#return full class name (preffered method)
sub name {
	return (shift)->{sig}->{string}; # for class it`s mean namespaceName::className 
}

#return name without namespace
sub simpleName { 
	return (shift)->{sig}->{name};
}

sub addConstructor {
	my ($this, $ctor) = @_;
	$this->{consturctors}->put($ctor);
}

sub constructors {
	my $this = shift;
	my $ctors = $this->{consturctors};
	
	if ($ctors->empty()) {
		return ($this->{defaultConstructor});
	}
	
	return $ctors->values();
}

sub constructor {
	my ($this, $ctor_sig) = @_;
	
	if ($this->{consturctors}->empty()) {
		return $this->{defaultConstructor};
	}
	
	return $this->{consturctors}->value($ctor_sig);
}

sub to_carg {
	my ($this, $type) = @_;
	
	return new CArg(arg_sig(
		$this->{sig}->{name},
		$this->{sig}->{namespace},
		$type
	));	
}

sub file {
	return (shift)->{file};
}

1;